function auc = AUC(y,p)

if length(unique(y)) == 1
    auc = sum(sign(p)==y)/length(y);
else
    auc = mean(mean(bsxfun(@(x,y)(sign(x-y)+1)/2,p(y==1),p(y==-1)')));
end

end

